<template>
	<view>
		<!-- <cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">{{ nickname?nickname:"设置" }}</block>
		</cu-custom> -->
		<view>
			<view class="padding-lr padding-tb-xs">
				<!-- <button class="cu-btn block shadow bg-gradual-blue margin lg" @click="gourl('../user/password')">修改密码</button> -->
				<!-- <button  class="cu-btn block shadow bg-white margin text-red lg" @click="loginOut()">退出登录</button> -->
				<view v-if="nickname">
					<button type="primary" class="margin buttonshadow" @click="gourl('../user/password')">修改密码</button>
					<button type="primary" class="margin buttonshadow" @click="gourl('../user/nickname')">修改昵称</button>
					<button type="warn" class="margin buttonshadow" @click="loginOut()">退出登录</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				nickname: uni.getStorageSync('userInfo'),
				ssuserid: uni.getStorageSync('userInfo')._id,
				userInfo: {},
			}
		},
		onLoad: function(option) {
			this.userInfo = uni.getStorageSync('userInfo')
			this.nickname = this.userInfo.nickname || this.userInfo.username
			this.ssuserid = this.userInfo._id
		},
		methods: {
			getPage: function() {
				var that = this;
				uniCloud.callFunction({
					name: "user-center",
					data: {
						"action": "get",
						id: this.ssuserid
					},
					success: function(e) {

						var res = e.result;
						if (res.error) {
							return false;
						}
						// console.log(res)
						that.user = res.data.user
					}
				})
			},
			gourl: function(url) {
				uni.navigateTo({
					url: url,
				})
			},
			loginOut: function() {
				// var that = this
				this.$store.dispatch('logout')
				// uniCloud.callFunction({
				// 	name: 'user-center',
				// 	data: {
				// 		action: 'logout',
				// 		uniIdToken: uni.getStorageSync('uniIdToken')
				// 	},
				// 	success(e) {
				// 		uni.removeStorageSync('uniIdToken')
				// 		uni.reLaunch({
				// 			url:"/pages/login/index"
				// 		})
				// 	},
				// 	fail(e) {
				// 		// console.error(e)
				// 	}
				// }) 								
			}
		},
	}
</script>

<style scoped lang="scss">

</style>
